Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PODVector Updates #3425

Merged
merged 1 commit into from
Jul 17, 2023
Merged

Conversation

WeiqunZhang
Copy link
Member

Remove deprecated and unused PolymorphicAllocator. It has been replaced by PolymorphicArenaAllocator.

Restrict PODVector's Allocator to std::allocator and AMReX's various Arena based allocators. This simplifies the implementation of PODVector, because std::allocator is stateless and Arena based allocators are simple even when it's polymorphic.

Fix a few issues of PODVectors with a PolymorphicArenaAllocator. For example, copy assignment operator should copy the Allocator. Copy constructor should consider the possibility that the other PODVector has a different type of Arena.

Add placeholders for potentially growing and shrinking memory allocation in-place that will be implemented in a follow-up PR.

Update PODVector's growth strategy. Hopefully this helps to reduce the memory consumption.

  • Always try to grow in-place.

  • For constructors, assign, operator=, resize & reserve, allocate the specified size without extra capacity.

  • For push_back & emplace_back, grow the capacity by a factor that is 1.5 by default, when there is need to grow.

  • For insert, the capacity grows either by a factor that is 1.5 by default or to the new size, whichever is greater, when there is need to grow.

@WeiqunZhang WeiqunZhang force-pushed the vector_resize branch 2 times, most recently from 4e795fc to 0268a79 Compare July 17, 2023 02:42
@WeiqunZhang WeiqunZhang marked this pull request as ready for review July 17, 2023 03:54
@WeiqunZhang WeiqunZhang requested a review from atmyers July 17, 2023 03:54
@WeiqunZhang WeiqunZhang force-pushed the vector_resize branch 4 times, most recently from 9b92e37 to 170dc48 Compare July 17, 2023 17:56
Remove deprecated and unused PolymorphicAllocator. It has been replaced by
PolymorphicArenaAllocator.

Restrict PODVector's Allocator to std::allocator and AMReX's various Arena
based allocators. This simplifies the implementation of PODVector, because
std::allocator is stateless and Arena based allocators are simple even when
it's polymorphic.

Fix a few issues of PODVectors with a PolymorphicArenaAllocator. For
example, copy assignment operator should copy the Allocator. Copy
constructor should consider the possibility that other PODVector has a
different type of Arena.

Add placeholders for potentially growing and shrinking memory allocation
in-place that will be implemented in a follow-up PR.

Update PODVector's growth strategy. Hopefully this helps to reduce the
memory consumption.

  * Always try to grow in-place.

  * For assign, operator=, resize & reserve, allocate the specified size
    without capacity.

  * For push_back & emplace_back, grow the capacity by a factor that is 1.5
    by default.

  * For insert, the capacity grows either by a factor that is 1.5 by default
    or to the new size, whichever is greater.
@WeiqunZhang WeiqunZhang merged commit 10b6cb2 into AMReX-Codes:development Jul 17, 2023
66 checks passed
@WeiqunZhang WeiqunZhang deleted the vector_resize branch July 17, 2023 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants